package com.ch.android.lookforkotlinv2.fragment

import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.ch.android.baselib.BaseBindingFragment
import com.ch.android.lookforkotlinv2.R
import com.ch.android.lookforkotlinv2.databinding.FragmentMainBinding
import com.ch.android.lookforkotlinv2.vm.MainFragmentModel
import com.ch.android.networklib.data.LiveTypeData

/**
 * Author: conghao
 * Date: 2023/12/26 16:13
 * Description: MainFragment
 */
class MainFragment : BaseBindingFragment<FragmentMainBinding>() {

    private var liveTypeData: LiveTypeData? = null
    companion object {
        private const val TAG = "MainFragment"
        private const val PARAM_ARG = "paramArg"
        public fun newInstance(liveTypeData: LiveTypeData): MainFragment {
            val fragment = MainFragment()
            val args = Bundle()
            args.putParcelable(PARAM_ARG, liveTypeData)
            fragment.arguments = args
            return fragment
        }
    }

    override fun getLayout() = R.layout.fragment_main

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Log.d(TAG, "onCreate: =============")
        liveTypeData = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            requireArguments().getParcelable(PARAM_ARG, LiveTypeData::class.java)
        } else {
            @Suppress("DEPRECATION")
            requireArguments().getParcelable<LiveTypeData>(PARAM_ARG)
        }
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val rootView = super.onCreateView(inflater, container, savedInstanceState)
        initData()
        return rootView
    }
    private fun initData() {
        binding.model = MainFragmentModel()
        binding.model?.title?.value = liveTypeData?.name
    }


}